package com.bamboowind.dead.maxlen;

import com.bamboowind.util.RabbitMqUtils;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

/**
 * @Author cpw
 * @Date 2022/11/2 8:57
 * 消费者C2
 */
public class Consumer02 {

    /**
     * 死信队列，与死信交换机绑定，消费者C2
     */
    public static final String DEAD_QUEUE = "dead-queue";


    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();

        System.out.println("等待接收消息:");
        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println("C2消费者接收到的消息为:" + new String(message.getBody(), "UTF-8"));
            // 手动确认
            channel.basicAck(message.getEnvelope().getDeliveryTag(), false);
        };

        CancelCallback cancelCallback = (consumerTag) -> {
            System.out.println("C2消费者取消消费操作");
        };

        channel.basicConsume(DEAD_QUEUE, false, deliverCallback, cancelCallback);
    }

}
